<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html>
<html>
<head>
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link
	href="${pageContext.request.contextPath }/admin/assets/css/bootstrap.min.css"
	rel="stylesheet" />
<link rel="stylesheet"
	href="${pageContext.request.contextPath }/admin/css/style.css" />
<link rel="stylesheet"
	href="${pageContext.request.contextPath }/admin/assets/css/ace.min.css" />
<link rel="stylesheet"
	href="${pageContext.request.contextPath }/admin/assets/css/font-awesome.min.css" />
<link rel="stylesheet"
	href="${pageContext.request.contextPath }/admin/Widget/zTree/css/zTreeStyle/zTreeStyle.css"
	type="text/css">
<link
	href="${pageContext.request.contextPath }/admin/Widget/icheck/icheck.css"
	rel="stylesheet" type="text/css" />
<script
	src="${pageContext.request.contextPath }/admin/js/jquery-1.9.1.min.js"></script>
<script
	src="${pageContext.request.contextPath }/admin/assets/js/bootstrap.min.js"></script>
<script
	src="${pageContext.request.contextPath }/admin/assets/js/typeahead-bs2.min.js"></script>
<script
	src="${pageContext.request.contextPath }/admin/assets/js/jquery.dataTables.min.js"></script>
<script
	src="${pageContext.request.contextPath }/admin/assets/js/jquery.dataTables.bootstrap.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/admin/js/H-ui.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/admin/js/H-ui.admin.js"></script>
<script
	src="${pageContext.request.contextPath }/admin/assets/layer/layer.js"
	type="text/javascript"></script>
<script
	src="${pageContext.request.contextPath }/admin/assets/laydate/laydate.js"
	type="text/javascript"></script>
<script src="${pageContext.request.contextPath }/admin/js/lrtk.js"
	type="text/javascript"></script>
<title>产品列表</title>
</head>
<body>
	<div class=" page-content clearfix">
		<div id="products_style">
			<div class="search_style">
				<div class="title_names">搜索查询</div>
				<ul class="search_content clearfix">
					<li><label class="l_f">产品名称</label><input name="" type="text"
						class="text_add" placeholder="输入品牌名称" style="width: 250px" /></li>
					<li style="width: 90px;"><button type="button"
							class="btn_search">
							<i class="icon-search"></i>查询
						</button></li>
				</ul>
			</div>
			<div class="border clearfix">
				<span class="l_f"> <a
					href="${pageContext.request.contextPath }/admin/stock_add.jsp"
					title="添加商品" class="btn btn-warning Order_form"><i
						class="icon-plus"></i>添加商品</a> <a id="batchDe" class="btn btn-danger"><i
						class="icon-trash"></i>批量删除</a>
				</span> <span class="r_f">共：<b>
				<s:property value="stocks.size()"/>
				</b>件商品
				</span>
			</div>
			<div class="table_menu_list" id="testIframe">
				<table class="table table-striped table-bordered table-hover"
					id="sample-table">
					<thead>
						<tr>
							<th width="25px"><label><input type="checkbox"
									class="ace"><span class="lbl"></span></label></th>
							<th width="80px">产品编号</th>
							<th width="250px">产品名称</th>
							<th width="100px">原价格</th>
							<th width="100px">现价</th>
							<th width="100px">车型</th>
							<th width="180px">型号</th>
							<th width="80px">作用</th>
							<th width="70px">数量</th>
							<th width="200px">操作</th>
						</tr>
					</thead>
					<tbody>
						<s:iterator value="stocks">
							<tr>
								<td width="25px"><label><input type="checkbox"
										class="ace" value="${stockId }"><span class="lbl"></span></label></td>
								<td width="80px">${stockId }</td>
								<td width="250px">${stockName }</td>
								<td width="100px">${stockMoney }</td>
								<td width="100px">${stockPrice }</td>
								<td width="100px">${stockCarModel.cname }</td>
								<td width="180px">${stockModel.acmodelName }</td>
								<td width="180px">${stockEffect }</td>
								<td width="180px">${stockNumber }</td>
								<td class="td-manage"> <a title="编辑"
									onclick="member_edit('编辑','${pageContext.request.contextPath }/findStockById','${stockId }','','510')"
									href="javascript:;" class="btn btn-xs btn-info"><i
										class="icon-edit bigger-120"></i></a> <a title="删除"
									href="javascript:;" onclick="member_del(this,'${stockId}')"
									class="btn btn-xs btn-warning"><i
										class="icon-trash  bigger-120"></i></a></td>
							</tr>
						</s:iterator>
					</tbody>
				</table>
			</div>
		</div>
	</div>
</body>

<script>
	jQuery(function($) {
		batchDes();
		var oTable1 = $('#sample-table').dataTable({
			"aaSorting" : [ [ 1, "desc" ] ],//默认第几个排序
			"bStateSave" : true,//状态保存
			"aoColumnDefs" : [
			//{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
			{
				"orderable" : false,
				"aTargets" : [ 0, 2, 3, 4, 5, 8, 9 ]
			} // 制定列不参与排序
			]
		});

		$('table th input:checkbox').on(
				'click',
				function() {
					var that = this;
					$(this).closest('table').find(
							'tr > td:first-child input:checkbox').each(
							function() {
								this.checked = that.checked;
								$(this).closest('tr').toggleClass('selected');
							});

				});

		$('[data-rel="tooltip"]').tooltip({
			placement : tooltip_placement
		});
		function tooltip_placement(context, source) {
			var $source = $(source);
			var $parent = $source.closest('table')
			var off1 = $parent.offset();
			var off2 = $source.offset();
			var w2 = $source.width();

			if (parseInt(off2.left) < parseInt(off1.left) + parseInt(w1 / 2))
				return 'right';
			return 'left';
		}
	});
	
	//批量删除
	var batchDes = function(){
		$('#batchDe').click(function(){
			var checkedObj = [];
			var i=0;
			var checks ="";
			$(":checkbox:checked").each(function(){//获取所有选中的按钮
					if($(this).val()!='on'){
						checks+=$(this).val()+",";
						checkedObj[i++]=this;
					}
			});
			if(checks==null||checks==""){
				layer.msg('请选中！！', {
					icon : 1,
					time : 1000
				});
				return ;
			}
			layer.confirm('确认要删除吗？', function(index) {
				 $.ajax({
					url:'${pageContext.request.contextPath }/batcheDeleteStock',
					type:"POST",
					data:'checks='+checks,
					dataType:'json',
					success:function(msg){
						if(msg){
							for(var i=0;i<checkedObj.length;i++){
								$(checkedObj[i]).parents("tr").remove();
							}
							layer.msg('已删除!', {
								icon : 1,
								time : 1000
							});
							checks="";
							checkedObj.clean();
						}
					},error:function(){
						layer.msg('删除失败!', {
							icon : 1,
							time : 1000
						});
					}
				}); 
			});
			
		});
	}
	
	
	laydate({
		elem : '#start',
		event : 'focus'
	});
	$(function() {
		$("#products_style").fix({
			float : 'left',
			//minStatue : true,
			skin : 'green',
			durationTime : false,
			spacingw : 30,//设置隐藏时的距离
			spacingh : 260,//设置显示时间距
		});

	});
</script>
<script type="text/javascript">
	var code;

	function showCode(str) {
		if (!code)
			code = $("#code");
		code.empty();
		code.append("<li>" + str + "</li>");
	}

	$(document).ready(function() {
		var t = $("#treeDemo");
		t = $.fn.zTree.init(t, setting, zNodes);
		demoIframe = $("#testIframe");
		demoIframe.bind("load", loadReady);
		var zTree = $.fn.zTree.getZTreeObj("tree");
		zTree.selectNode(zTree.getNodeByParam("id", '11'));
	});
	
	/*产品-编辑*/
	function member_edit(title, url, id, w, h) {
		layer_show(title, url+"?stockId="+id, w, h);
	}

	/*产品-删除*/
	function member_del(obj, id) {
		layer.confirm('确认要删除吗？', function(index) {
			 $.ajax({
				url:'${pageContext.request.contextPath }/deleteStock',
				type:"POST",
				data:'stockId='+id,
				dataType:'json',
				success:function(msg){
					if(msg){
						$(obj).parents("tr").remove();
						layer.msg('已删除!', {
							icon : 1,
							time : 1000
						});
					}
				},error:function(){
					layer.msg('删除失败!', {
						icon : 1,
						time : 1000
					});
				}
			}); 
		});
	}
	
	
	
	
	//面包屑返回值
	var index = parent.layer.getFrameIndex(window.name);
	parent.layer.iframeAuto(index);
	$('.Order_form').on('click', function() {
		var cname = $(this).attr("title");
		var chref = $(this).attr("href");
		var cnames = parent.$('.Current_page').html();
		var herf = parent.$("#iframe").attr("src");
		parent.$('#parentIframe').html(cname);
		parent.$('#iframe').attr("src", chref).ready();
		;
		parent.$('#parentIframe').css("display", "inline-block");
		parent.$('.Current_page').attr({
			"name" : herf,
			"href" : "javascript:void(0)"
		}).css({
			"color" : "#4c8fbd",
			"cursor" : "pointer"
		});
		parent.layer.close(index);

	});
</script>
</html>